package day2;

import day2.pet.Dog;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import  java.util.Set;
/**
 * @author oldliu
 * @since 1.0
 */
public class SetTest {
    public static void main(String[] args) {
        //set特点：无序，保证不重复  ?get
        Set set=new HashSet();//TreeSet
        set.add(233);
        set.add("dog");
        set.add(233);
        set.add("cat");
        set.add("dog");
        System.out.println(set.size());//3
        System.out.println(set);
        //迭代：
        System.out.println(">>>>>>>>>for>>>>>>>>>>>");
        for(Object o:set)
            System.out.println(o);
        System.out.println(">>>>>>>to array>>>>>>>>>>>>>");
        Object[] ar = set.toArray();
        System.out.println(Arrays.toString(ar));
        System.out.println(">>>>>>>>>>>迭代器>>>>>>>>>>>>>>>");
        Iterator ir = set.iterator();
        while(ir.hasNext()){
            Object o=ir.next();
            System.out.println(o);
        }
        System.out.println(">>>>>>>>>加对象>>>>>>>>>>>>>>>>>>>");
        Set set2=new HashSet();
        set2.add(new Dog("小花花","公",100,100));
        set2.add(new Dog("王二狗","公",66,100));
        set2.add(new Dog("小花狗","公",44,100));
        set2.add(new Dog("大黄","公",88,100));
        set2.add(new Dog("小花花","母",66,88));
        System.out.println("set2大小："+set2.size());
        for(Object o:set2)
        {
            Dog dog=(Dog)o;
            System.out.println(dog);
        }
    }

}
